import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import jQuery from 'jquery'

//exel
// import Blob from './assets/js/Blob'
// import Export2Excel from './assets/js/Export2Excel.js'

//引入 配置 axios
import axios from "axios"
Vue.prototype.axios = axios
//axios.defaults.withCredentials = true;
axios.defaults.baseURL = "https://vip.bearing.cn/" //配置访问接口的
//axios.defaults.baseURL = "http://mobile.bearing.cn/" //配置访问
import element from "element-ui"
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(element)

import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
Vue.use(Antd)

//富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
Vue.use(VueQuillEditor)

//生成pdf
// import html2canvas from 'html2canvas';
// Vue.use(html2canvas);

import jspdf from 'jspdf';
Vue.use(jspdf);

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import Print from 'vue-print-nb'//打印
Vue.use(Print); //注册打印

import VueI18n from 'vue-i18n'
import LangENUS from './common/lang/en-us'
import LangZHCN from './common/lang/zh-cn'
Vue.use(VueI18n)
import VueFroala from 'vue-froala-wysiwyg'

// 引入 Froala Editor js file.
require('froala-editor/js/froala_editor.pkgd.min')

//引入中文语言包
require('froala-editor/js/languages/zh_cn')

//引入 Froala Editor css files.
require('froala-editor/css/froala_editor.pkgd.min.css')
require('font-awesome/css/font-awesome.css')//此处可在index.html中引入：font-awesome cdn地址：<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
require('froala-editor/css/froala_style.min.css')

window.$ = jQuery
window.jQuery = jQuery
// Import and use Vue Froala lib.
Vue.use(VueFroala)

const i18n = new VueI18n({
  locale: 'zh-cn',
  messages: {
    'en-us': LangENUS,
    'zh-cn': LangZHCN
  }
})


router.beforeEach((to, from, next) => {
  let sqdwid = sessionStorage.getItem('sqdwid');
  let phone = sessionStorage.getItem('phone');
  // console.log(sqdwid);
  // console.log(phone);

  axios.interceptors.request.use(function (config) { // 在发送请求之前做些什么

    // config.headers['sqdwid'] = store.state.bbl_sqdwid
    // config.headers['phone'] = store.state.bbl_phone;
    config.headers['token'] = store.state.token;
    // this.$store.state.token
    return config;
  }, function (error) {
    // 对请求错误做些什么

    return Promise.reject(error);
  });
  next()
  if (to.matched.length === 0) { //没有匹配到当前路由
    next('/error')
  } else if (!sqdwid && !phone && to.path !== '/login' && to.path !== '/reg' && to.path !== '/passwordNew' && to.path !== '/viplogin') {
    //如果没有登录，跳转到登录页面
    next('/login')
  } else {
    if ((to.path === '/login' || to.path === '/reg' || to.path === '/passwordNew' || to.path === '/viplogin') && sqdwid && phone) {
      //如果已经登录，却尝试访问登录页面或者错误页面，将继续保持原本的页面
      // next(from.path)
      next()
    } else {

      // axios.interceptors.request.use(function (config) { // 在发送请求之前做些什么

      //   config.headers['sqdwid'] = sqdwid;
      //   config.headers['phone'] = phone;
      //   console.log('main--sqdwid-----', config)

      //   return config;
      // }, function (error) {
      //   // 对请求错误做些什么

      //   return Promise.reject(error);
      // });
      next()
    }

  }
  // console.log('main--phone-----',config.headers['phone'])
})

Vue.config.productionTip = false

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')